package week3.onClass.exer02;

import java.util.Scanner;

public class Main {

    private static int curCount = 1;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        int res = (int) Math.pow(2, k);
        int rows = res;
        int cols = res;
        int[][] matrix = new int[rows][cols];
        int specialRow = scanner.nextInt();
        int specialCol = scanner.nextInt();
        matrix[specialRow][specialCol] = 0;
        partition(matrix, 0, rows - 1, 0, cols - 1, specialRow, specialCol);
        matrix[specialRow][specialCol] = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                System.out.printf("%4s", matrix[i][j]);
            }
            System.out.println();
        }
    }

    private static void partition(int[][] matrix, int upRow, int downRow, int leftCol, int rightCol, int specialRow, int specialCol) {
        if (upRow == downRow && leftCol == rightCol) {
            return;
        }
        int midRow = (upRow + downRow) / 2;
        int midCol = (leftCol + rightCol) / 2;
        int copyCount = curCount;



        curCount++;
        if (upRow <= specialRow && specialRow <= midRow && leftCol <= specialCol && specialCol <= midCol) {
            // 如果特殊点在左上方
            partition(matrix, upRow, midRow, leftCol, midCol, specialRow, specialCol);
        } else {
            partition(matrix, upRow, midRow, leftCol, midCol, midRow, midCol);
            matrix[midRow][midCol] = copyCount;
        }
        if (upRow <= specialRow && specialRow <= midRow && midCol + 1 <= specialCol && specialCol <= rightCol) {
            // 如果特殊点在右上方
            partition(matrix, upRow, midRow, midCol + 1, rightCol, specialRow, specialCol);
        } else {
            partition(matrix, upRow, midRow, midCol + 1, rightCol, midRow, midCol + 1);
            matrix[midRow][midCol + 1] = copyCount;
        }
        if (midRow + 1 <= specialRow && specialRow <= downRow && leftCol <= specialCol && specialCol <= midCol) {
            // 如果特殊点在左下方
            partition(matrix, midRow + 1, downRow, leftCol, midCol, specialRow, specialCol);
        } else {
            partition(matrix, midRow + 1, downRow, leftCol, midCol, midRow + 1, midCol);
            matrix[midRow + 1][midCol] = copyCount;
        }
        if (midRow + 1 <= specialRow && specialRow <= downRow && midCol + 1 <= specialCol && specialCol <= rightCol) {
            // 如果特殊点在右下方
            partition(matrix, midRow + 1, downRow, midCol + 1, rightCol, specialRow, specialCol);
        } else {
            partition(matrix, midRow + 1, downRow, midCol + 1, rightCol, midRow + 1, midCol + 1);
            matrix[midRow + 1][midCol + 1] = copyCount;
        }

    }
}
